package org.tacticalTroopers.jme.common.message;





import java.util.HashMap;
import java.util.Map;

import org.tacticalTroopers.jme.server.object.ServerElement;

import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.network.message.Message;
import com.jme3.network.serializing.Serializable;

@Serializable()
public class Element extends Message{

	Vector3f position = new Vector3f();
	Quaternion rotation = new Quaternion();
	Vector3f size = new Vector3f();
	Map<String,Object> attributes = new HashMap<String,Object>();
	Id id;
	
	public static final String PLAYER = "Player";
	public static final String BULLET = "Bullet";
	public static final String ELEMENT = "Element";
	String type;
	
	
	public Element(){
		
	}

	public void setId(Id id) {
		this.id = id;
	}

	public Id getId() {
		return id;
	}

	public Vector3f getSize() {
		return size;
	}



	public void setSize(javax.vecmath.Vector3f size) {
		setSize(size.x, size.y, size.z);
	}

	public void setSize(Float x,Float y, Float z) {
		this.size.set(x,y,z);
	}


	public void setPosition(Float x,Float y, Float z){
		this.position.set(x, y, z);
	}

	public void setPosition(javax.vecmath.Vector3f position){
		setPosition(position.x, position.y, position.z);
	}

	public Element setRotation(Float rotX,Float rotY, Float rotZ,Float w){
		rotation.set(rotX,rotY,rotZ,w);
		return this;
	}
	
	public Element setRotation(Float rotX,Float rotY, Float rotZ){
		rotation.fromAngleAxis(rotX, new Vector3f(1f,0f,0f));
		rotation.fromAngleAxis(rotY, new Vector3f(0f,1f,0f));
		rotation.fromAngleAxis(rotZ, new Vector3f(0f,0f,1f));
		return this;
	}
	
	public Quaternion getRotation() {
		return rotation;
	}


	public Vector3f getPosition(){
		return position;
	}
	
	@Override
	public String toString() {
		return "Element{id:"+id+" position:"+position+" rotation:"+rotation+" size:"+size+"}";
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}
	
	public Element setAttribute(String key,Boolean bool) {
		attributes.put(key.intern(), bool);
		return this;
	}
	
	public Element setAttribute(String key,String value) {
		attributes.put(key.intern(), value);
		return this;
	}
	
	public Boolean getAttributeBoolean(String key,Boolean defaultValue){
		Boolean b = (Boolean)attributes.get(key.intern());
		return b==null?defaultValue:b;
	}
	
	public String getAttributeString(String key){
		return (String)attributes.get(key.intern());
	}
}
